/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * introduction:
 *  触摸传感驱动
 */

#include "hi_io.h" 
#include "hi_gpio.h"
#include "hi_adc.h"
#include "iot_gpio.h"
#include "touch_sensor.h"

void TouchSensorInit(void)
{
    IoTGpioInit(TOUCH_ADC9);
    hi_io_set_func(TOUCH_ADC9, HI_IO_FUNC_GPIO_9_GPIO);
    hi_gpio_set_dir(TOUCH_ADC9, HI_GPIO_DIR_IN);
    hi_io_set_pull(HI_IO_NAME_GPIO_9, HI_IO_PULL_DOWN);
    
}

// 读取touch sensor电压值
float Get_touch_val(void)
{
    unsigned short int data;
    if (hi_adc_read(HI_ADC_CHANNEL_4, &data, HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_DEFAULT, 0) == 0)
    {
        printf("ADC4 %d \n", data);
        return data;
    }
    else
        return -1;
}